package demo;

import java.util.Arrays;
import java.util.Scanner;

/**
 * @Author liangzai
 * @Description:
 */
public class Main {
    //求阶乘
    public static void main1(String[] args) {
        Scanner scanner = new Scanner(System.in);
        long K = scanner.nextLong();
        long left = 1;
        long right = Long.MAX_VALUE-1;
        while(left<right) {
            long mid = left + (right - left)/2;
            if(K<=calc(mid)) {
                right = mid;
            }else {
                left = mid+1;
            }
        }
        if(calc(left)!=K) {
            System.out.println(-1);
        }else {
            System.out.println(left);
        }
    }

    private static long calc(long val) {
        long ret = 0;
        while(val!=0) {
            ret += val/5;
            val /= 5;
        }
        return ret;
    }

    //最少刷题数
    public static void main3(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] nums = new int[n+1];
        for (int i = 1; i <= n; i++) {
            nums[i] = scanner.nextInt();
        }
        int[] copynums = Arrays.copyOf(nums, n+1);
        Arrays.sort(nums);
        int val = nums[n/2+1];
        int left = 1;
        int right = n;
        while(left<right) {
            int mid = left + (right-left)/2;
            if(nums[mid]<val) {
                left = mid+1;
            }else {
                right = mid;
            }
        }
        int key1 = left-1;
        left = 1;right = n;
        while(left<right) {
            int mid = left + (right-left+1)/2;
            if(nums[mid]>val) {
                right = mid - 1;
            }else {
                left = mid;
            }
        }
        int key2 = n-left;
        int[] ret = new int[n+1];
        System.out.println(val);
        for (int i = 1; i <= n; i++) {
            if(copynums[i]==val) {
                if(key1>=key2) {
                    ret[i] = 0;
                }else {
                    ret[i] = 1;
                }
            }else {
                if(key1<=key2) {
                    ret[i] = val-copynums[i]>0?val-copynums[i]+1:0;
                }else{
                    ret[i] = val-copynums[i]>0?val-copynums[i]:0;
                }
            }
            System.out.print(ret[i]+" ");
        }
    }

    public static void main2(String[] args) {
        long startTime = System.nanoTime();
        long endTime;
        long duration;
        int count = 0;

        // 循环一秒钟
        do {
            // 这里可以是一些简单的操作，比如递增计数器
            count++;
            endTime = System.nanoTime();
            duration = (endTime - startTime) / 1_000_000; // 转换为毫秒
        } while (duration < 1000); // 循环一秒钟

        System.out.println("在一秒钟内循环了 " + count + " 次");
    }


    public static void main4(String[] args) {
        long pcur = System.currentTimeMillis();
        long count = 0;
        long time = System.currentTimeMillis();
        while(time<=pcur+1000) {
            count++;
            time = System.currentTimeMillis();
        }
        System.out.println(count);
    }


    //约瑟夫环问题
    public static void main5(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        int[] nums = new int[n+1];
        int count = 0;
        int flag = 1;
        //int pcur = 1;
        for (int i = 1; count!=n; i=(i)%(n)+1) {
            if(nums[i]==0) {
                if(flag==m) {
                    System.out.print(i+" ");
                    nums[i] = 1;
                }
                flag = flag%m+1;
                count = 0;
            }else {
                count++;
            }
        }
    }

    //卡片
    public static void main6(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        long sum = 1;
        int count = 1;
        while(sum<n) {
            sum += count+1;
            count++;
        }
        System.out.println(count);
    }

}
